package com.example.tao.mycar;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.view.WindowCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

/**
 * Created by Tao on 2016/3/10.
 */
public class MyActionBarActivity extends AppCompatActivity implements Toolbar.OnMenuItemClickListener {

    protected MyApplication app = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (MyApplication) getApplication();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_MODE_OVERLAY);
    }

    protected void setToolBar(Toolbar toolBar, DrawerLayout drawerLayout) {
        setSupportActionBar(toolBar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        ActionBarDrawerToggle mDrawerToggle;
        mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
        mDrawerToggle.syncState();
        drawerLayout.setDrawerListener(mDrawerToggle);
    }

    protected void setToolBar(Toolbar toolBar, boolean canBack) {
        toolBar.setTitle("");
        setSupportActionBar(toolBar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(canBack);
    }

    protected void setToolBar(String title, boolean canBack) {
        Toolbar mToolbar = (Toolbar) findViewById(R.id.custom_actionbar);
        TextView mTextView = (TextView) findViewById(R.id.toolbar_title);
        if (title == null || title.isEmpty()) {
            mTextView.setText(R.string.app_name);
        } else {
            mTextView.setText(title);
        }
        mTextView.setTextColor(getResources().getColor(R.color.white));
        mTextView.setTextSize(20f);
        setToolBar(mToolbar, canBack);
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        return false;
    }
}
